from sqlalchemy import Column, String, DECIMAL, func, Boolean, Date
from sqlalchemy.dialects.mysql import TINYINT, BIGINT
from pydantic import BaseModel
from server.model import BaseOrm
from datetime import datetime
from server import db


class BookingStatus:
    NotPaid = 0
    Paid = 1
    Used = 2
    Expired = 3


class BookingCreate(BaseModel):
    name: str
    address: str
    open_time: datetime
    close_time: datetime


class BookingSchema(BookingCreate):
    id: int

    class Config:
        orm_mode = True


# 订场记录
class Booking(BaseOrm):
    __tablename__ = 'booking'
    gym_id = Column(BIGINT(20, unsigned=True), nullable=False, index=True, comment="球馆id")
    field_id = Column(BIGINT(20, unsigned=True), nullable=False, index=True, comment="场地id")
    field_name = Column(String(64), nullable=False, server_default="", comment="场地名称")
    user_id = Column(BIGINT(20, unsigned=True), nullable=False, index=True, comment="用户id")
    user_phone = Column(String(16), index=True, nullable=False, server_default="", comment="手机号码")
    order_id = Column(BIGINT(20, unsigned=True), nullable=False, index=True, comment="订单id")
    book_hour = Column(TINYINT(unsigned=True), nullable=False, server_default="0", comment="预订时段 0-24")
    book_date = Column(Date, comment="日期")
    price = Column(DECIMAL(6, 2), nullable=False, server_default="0", comment="价格")
    status = Column(TINYINT(unsigned=True), nullable=False, server_default="0", comment="状态: 0:未支付 1:已支付 2:已使用 3:已过期")
    remind_on = Column(Boolean, nullable=False, server_default="0", index=True, comment="开启提醒: 0:否 1:是")
    remark = Column(String(255), nullable=False, server_default="", comment="备注")


db.create_all()
